package com.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.entity.Order;
import com.project.entity.OrderCount;
import com.project.mapper.TOrderMapper;
import com.project.service.ITOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangyang
 * @since 2021-10-06
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, Order> implements ITOrderService {

    @Autowired
    private TOrderMapper orderMapper;

    @Override
    public List<Order> findByCodeAndTime(String code, LocalDate time, String who) {
        if (who.equals("business")) {
            return orderMapper.findByBusinessCodeAndTime(code, time);
        }
        if (who.equals("custom")) {
            return orderMapper.findByCustomCodeAndTime(code, time);
        }
        if (who.equals("rider")) {
            return orderMapper.findByRiderCodeAndTime(code, time);
        }
        return null;
    }

    @Override
    public OrderCount findCount(String code, LocalDate time, String who) {
        if (who.equals("business")) {
            OrderCount countByBusiness = orderMapper.findCountByBusiness(code, time);
            OrderCount byBusiness = orderMapper.findByBusiness(code, time.getMonthValue());
            countByBusiness.setMonthMoney(byBusiness.getMonthMoney());
            countByBusiness.setMonthNum(byBusiness.getMonthNum());
            return countByBusiness;
        }
        if (who.equals("custom")) {
            OrderCount countByBusiness = orderMapper.findCountByCustom(code, time);
            OrderCount byBusiness = orderMapper.findByCustom(code, time.getMonthValue());
            countByBusiness.setMonthMoney(byBusiness.getMonthMoney());
            countByBusiness.setMonthNum(byBusiness.getMonthNum());
            return countByBusiness;
        }
        if (who.equals("rider")) {
            OrderCount countByBusiness = orderMapper.findCountByRider(code, time);
            OrderCount byBusiness = orderMapper.findByRider(code, time.getMonthValue());
            countByBusiness.setMonthMoney(byBusiness.getMonthMoney());
            countByBusiness.setMonthNum(byBusiness.getMonthNum());
            return countByBusiness;
        }
        return null;
    }
}
